<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;

class Article extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index(){
        echo 1;
    }

    public function article($art=0){
        if($art==0){
            return $this->error('404');
            exit;
        }
        #获取
        $artid=$art;

        #查库
        $art = model('Getitem')->check($artid);
        if(empty($art)){
            return $this->error('没找到文章');
            exit;
        }

        #查类型
        $typeid = $art['category_id'];
        $type = $this->ctype($typeid,$artid);
        
        #推荐信息-10篇
        $tjxx = model('Getitem')->itemRand(10);

        #最新资讯-8篇
        $zxxx = model('Getitem')->itemA('updatetime','desc',8);

        #热门内容-8篇
        $rmnr = model('Getitem')->itemA('views','desc',8);

        #相关文章-10篇
        $xgwz = model('Getitem')->item($art['category_id'],10);

        #所在的位置-$type['data']
        $code = $type['code'];
        $url = $type['data'];
        $turl = $type['turl'];

        #文章标题
        $title = $art['title'];

        #文章时间
        $time = $art['releasetime'];

        #文章作者
        $author = '湖北专升本网';

        #文章内容
        $content = $art['content'];

        #文章培训信息尾巴
        

        #阅读次数
        $views = model('Getitem')->addview($artid);
        $views += $art['views'];

        #上一篇id和标题
        $prev = model('Getitem')->otherArt($artid,'<');
        if(empty($prev)){
            $prev['url'] = 'javascript:;';
            $prev['title'] = '没有了';
        }else{
            $prev['type'] = model('Getitem')->getcate($prev['category_id'])['nickname'];
            $prev['url'] = '/article/article/art/'.$prev['id'].'.html';
        }

        #下一篇id和标题
        $next = model('Getitem')->otherArt($artid,'>');
        if(empty($next)){
            $next['url'] = 'javascript:;';
            $next['title'] = '没有了';
        }else{
            $next['type'] = model('Getitem')->getcate($next['category_id'])['nickname'];
            $next['url'] = '/article/article/art/'.$next['id'].'.html';
        }

        $this->assign([
            'web_title' =>  $title,
            'web_keywords'  =>  $title,
            'web_description'   =>  $title,
            'tjxx'      =>  $tjxx,
            'zxzx'      =>  $zxxx,
            'rmnr'      =>  $rmnr,
            'xgwz'      =>  $xgwz,
            'code'      =>  $code,
            'url'       =>  $url,
            'turl'      =>  $turl,
            'title'     =>  $title,
            'time'      =>  $time,
            'author'    =>  $author,
            'content'   =>  $content,
            'views'     =>  $views,
            'prev'      =>  $prev,
            'next'      =>  $next,
        ]);
        return $this->fetch();
    }

    protected function ctype($type,$id){
        $type = model('Getitem')->getcate($type);
        $name = $type['name'];
        $nick = $type['nickname'];
        if($type['pid']!=0){
            $type_p = model('Getitem')->getcate($type['pid']);
            $pname = $type_p['name'];
            $pnick = $type_p['nickname'];
        }else{
            $pname=0;
            $pnick='';
        }
        $data=[
            'pname'     =>  $pname,
            'pnick'     =>  $pnick,
            'name'      =>  $name,
            'nick'      =>  $nick,
            'id'        =>  $id,
        ];
        $ret = $this->getname($data);
        
        return $ret;
    }

    //普通专升本院校文章
    public function yx($art=0){
        
        if($art==0){
            return $this->error('没找到相关内容');
            exit;
        }
        $yx = model('Getyx')->getyx($art);
        
        //招生简章 5篇
        $zsjz = model('Getyx')->getjz($yx['title'],'招生简章',5);

        //最新动态 10篇
        $zxdt = model('Getyx')->getjz($yx['title'],'专业',10);
        if(empty($stzl)){
            $zxdt = model('Getyx')->getjz('',date('Y'),8);
        }

        //推荐信息 8
        $tjxx = model('Getyx')->getjz($yx['title'],'',8);
        
        //试题资料 8篇
        $stzl = model('Getyx')->getjz($yx['title'],'题',8);
        if(empty($stzl)){
            $stzl = model('Getyx')->getjz('','试题',8);
        }

        //获取院校年份及专业
        $zsjh = model('Getyx')->yxzy_item($art);
        //dump($zsjh);
        

        $this -> assign([
            'web_title' =>  $yx['title']." | 普通专升本院校",
            'web_keywords'  =>  $yx['title'].",普通专升本院校,专升本,普通专升本",
            'web_description'   =>  $yx['title']."专升本是湖北省历年普通专升本举办高校之一，欢迎广大考生报考！".$yx['title']."专升本是湖北省所有高校中的一本院校普通专升本。-湖北普通专升本专题频道普通专升本院校",
            'yx'    =>  $yx,
            'zsjz'  =>  $zsjz,
            'zxdt'  =>  $zxdt,
            'tjxx'  =>  $tjxx,
            'stzl'  =>  $stzl,
            'zsjh'  =>  $zsjh,
        ]);
       return $this -> fetch();
    }

    //自考专升本院校文章
    public function zkyx($art=0){
        if($art==0){
            return $this->error('没找到相关内容');
            exit;
        }
        $yx = model('Getyx')->getyx($art);
        $this -> assign([
            'web_title' =>  $yx['title']." | 自考院校",
            'web_keywords'  =>  $yx['title'].",自考专升本院校",
            'web_description'   =>  $yx['title'].",自考专升本院校",
            'yx'    =>  $yx,
        ]);
        
        return $this -> fetch();

    }

    //普通专升本专业
    public function zy($art=0){
        if($art==0){
            return $this->error('没找到相关内容');
            exit;
        }

        $zy = model('Getyx')->getzy($art);
        $zy['yx'] = model('Getyx')->getyx($zy['yuanxiao_id'])['title'];
        //echo $zy['title'];

        //zy2018
        $zy2018 = model('Getyx')->zylike(2018,$zy['title']);

        $zy2017 = model('Getyx')->zylike(2017,$zy['title']);

        $zy2016 = model('Getyx')->zylike(2016,$zy['title']);

        $zy2015 = model('Getyx')->zylike(2015,$zy['title']);

        $zy2014 = model('Getyx')->zylike(2014,$zy['title']);

        $zy2013 = model('Getyx')->zylike(2013,$zy['title']);

        $zy2012 = model('Getyx')->zylike(2012,$zy['title']);

        $zy2011 = model('Getyx')->zylike(2011,$zy['title']);

        $this -> assign([
            'web_title' =>  $zy['title']."专升本专业考试科目、录取分数线和参考教材_普通专升本招生专业_湖北专升本网",
            'web_keywords'  =>  $zy['title']."专升本专业考试科目、录取分数线和参考教材_普通专升本招生专业_湖北专升本网",
            'web_description'   =>  $zy['title']."专升本专业考试科目、录取分数线和参考教材_普通专升本招生专业_湖北专升本网",
            'zy'    =>  $zy,
            'zy2018'    =>  $zy2018,
            'zy2017'    =>  $zy2017,
            'zy2016'    =>  $zy2016,
            'zy2015'    =>  $zy2015,
            'zy2014'    =>  $zy2014,
            'zy2013'    =>  $zy2013,
            'zy2012'    =>  $zy2012,
            'zy2011'    =>  $zy2011, 
        ]);
        return $this->fetch();

    }

    //自考专升本专业
    public function zkzy($art=0){
        if($art==0){
            return $this->error('没找到相关内容');
            exit;
        }
        $zy = model('Getyx')->getzkzy($art);
        $zy['yx'] = model('Getyx')->getyx($zy['yuanxiao_id'])['title'];
        //dump($zy);
        //获取相关推荐
        $zkyx = model('Getyx')->getzkyxtj($zy['yuanxiao_id']);

        $zy2018 = model('Getyx')->zylike(2018,$zy['title']);
        $zy2017 = model('Getyx')->zylike(2017,$zy['title']);
        $zy2016 = model('Getyx')->zylike(2016,$zy['title']);
        $zy2015 = model('Getyx')->zylike(2015,$zy['title']);
        $zy2014 = model('Getyx')->zylike(2014,$zy['title']);
        $zy2013 = model('Getyx')->zylike(2013,$zy['title']);
        $zy2012 = model('Getyx')->zylike(2012,$zy['title']);
        $zy2011 = model('Getyx')->zylike(2011,$zy['title']);

        $this -> assign([
            'web_title' =>  " | 自考院校专业",
            'web_keywords'  =>  ",自考院校专业",
            'web_description'   =>  ",自考专升本院校专业",
            'zy'    =>  $zy,
            'zkyx'  =>  $zkyx,
            'zy2018'    =>  $zy2018,
            'zy2017'    =>  $zy2017,
            'zy2016'    =>  $zy2016,
            'zy2015'    =>  $zy2015,
            'zy2014'    =>  $zy2014,
            'zy2013'    =>  $zy2013,
            'zy2012'    =>  $zy2012,
            'zy2011'    =>  $zy2011,
        ]);
        return $this->fetch();


    }

    protected function getname($data){
        if($data['pname']!='0')
            $ret=[
                'code' => 1,
                'data'   =>[
                    [
                        'name' =>  $data['pname'],
                        'url'  =>  "/".$data['pnick'],
                    ],
                    [
                        'name'  =>  $data['name'],
                        'url'   =>  '/artitem/artitem/item/'.$data['nick'].'.html',
                    ],      
                ],
                'turl'  =>  '/article/article/art/'.$data['id'].'.html',
                        
            ];
        else
            $ret=[
                'code' => 0,
                'data'  =>
                [
                    'name' =>  $data['name'],
                    'url'  =>  '/'.$data['nick']
                ],    
                'turl'  =>  '/article/article/art/'.$data['id'].'.html',
            ];
        return $ret;
            
    }

}
